package com.jrh.dal;

import java.util.List;
import java.util.Map;

import com.jrh.domain.common.Page;
import com.jrh.domain.entity.Brand;

/**
 * 品牌DAO实现
 * 
 * @author yout 2012-7-22 上午10:50:21
 */
public class BrandDao extends BaseDao<Brand> {

    public BrandDao(){
        this.namespace = "jrh.single.brand";
    }

    @SuppressWarnings("unchecked")
    public Page<Brand> listByCondition(Brand brand, Integer start, Integer pageSize, Long mallId) {
        Map<String, Object> map = this.getPageMap(start, pageSize);
        map.put("style", brand.getStyle());
        map.put("mallId", mallId);
        List<Brand> list = (List<Brand>) sqlMapClientTemplate.queryForList(namespace + "." + "listByCondition", map);
        Integer count = (Integer) sqlMapClientTemplate.queryForObject(namespace + "." + "listByCondition_count", map);
        return new Page<Brand>(list, start, pageSize, count);

    }

    public List<Brand> listAll() {
        return (List<Brand>) sqlMapClientTemplate.queryForList(namespace + "." + "listAll");
    }

    public Brand getBrandByUserId(long userId) {
        return (Brand) sqlMapClientTemplate.queryForObject(namespace + "." + "getBrandByUserId", userId);
    }

    public Long insert(Brand brand) {
        return (Long) sqlMapClientTemplate.insert(namespace + "." + "create", brand);
    }
}
